package com.b2bpsssm.controller.sysmanage;/**
 * @author JunYu
 * @create 2022-08-12--17:41
 */

import com.b2bpsssm.common.R;
import com.b2bpsssm.ov.SysRole_MenuInOV;
import com.b2bpsssm.pojo.SysRole;
import com.b2bpsssm.simulate.GenerateSysRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

/**
 * @program: B2BPSSMSystem
 * @description: 角色管理相关控制器
 * @author: JunYu
 * @create: 2022-08-12 17:41
 **/
@Controller
@EnableSwagger2
@RequestMapping(value = "/sys_role")
@Api(value = "角色管理", tags = "角色管理api")
public class SysRoleController {

    //添加角色接口
    @RequestMapping(value = "/addRole", method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "添加角色接口", notes = "添加角色接口，传入原型图所需参数", httpMethod = "post", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "SysRole_MenuInOV", value = "原型图中所需参数", paramType = "Object", dataType = "json", required = true)
            }
    )
    public R addRole(@RequestBody SysRole_MenuInOV sysRole_menuInOV) {

        R r = new R();
        r.setCode(200);
        r.setMassage("添加成功,添加的角色名称为：" + sysRole_menuInOV.getName() + "，添加的权限有" + sysRole_menuInOV.getMenu_ids());
        return r;
    }

    //删除角色接口
    @RequestMapping(value = "/delRoleById", method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "删除角色", notes = "通过角色id删除角色", httpMethod = "post", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "id", value = "角色id", paramType = "int", dataType = "String", required = true)
            }
    )
    public R delRoleById(@RequestParam("id") int id) {
        R r = new R();
        r.setCode(200);
        r.setMassage("删除成功，删除的角色id为" + id);
        return r;
    }

    //批量删除角色接口
    @RequestMapping(value = "/batchDelRoles", method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "批量删除角色", notes = "传入id数组批量删除角色", httpMethod = "", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "ids", value = "角色id数组", paramType = "List<Integer>", dataType = "String", required = true)
            }
    )
    public R batchDelRoles(@RequestBody List<Integer> ids) {
        R r = new R();
        r.setCode(200);
        r.setMassage("批量删除成功，删除的角色的id为" + ids);
        return r;
    }

    //查询所有角色
    @RequestMapping(value = "/findRoleList", method = RequestMethod.GET)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "查询所有角色", notes = "输入当前页码和页面长度来查询所有角色", httpMethod = "get", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "currentPage", value = "当前页码", paramType = "int", dataType = "String", required = true),
                    @ApiImplicitParam(name = "pageSize", value = "页码长度", paramType = "int", dataType = "String", required = true)
            }
    )
    public R findRoleList(@RequestParam("currentPage") int currentPage, @RequestParam("pageSize") int pageSize) {
        R r = new R();
        r.setCode(200);
        r.setMassage("查询所有角色成功");
        r.setData(GenerateSysRole.generateSysRoleList(pageSize));
        return r;
    }

    //导出所有角色
    @RequestMapping(value = "/exportRoleLIst", method = RequestMethod.GET)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "导出所有角色", notes = "导出所有角色，不需要传入任何参数", httpMethod = "get", response =R.class)
    public R exportRoleLIst() {
        R r = new R();
        r.setCode(200);
        r.setMassage("导出角色成功");
        return r;
    }

    //根据角色名称查询角色
    @RequestMapping(value = "/findRolesByName", method = RequestMethod.GET)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "根据角色名称查询角色", notes = "输入角色名称查询角色", httpMethod = "get", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "role_name", value = "角色名称", paramType = "String", dataType = "String", required = true)
            }
    )
    public R findRolesByName(@RequestParam("role_name") String role_name) {
        R r = new R();
        r.setCode(200);
        r.setMassage("根据角色名称查询角色成功");
        r.setData(GenerateSysRole.generateRole());
        return r;
    }

    //编辑角色
    @RequestMapping(value = "/updateRoleById", method = RequestMethod.POST)
    @ResponseBody
    //Swagger配置
    @ApiOperation(value = "编辑角色", notes = "编辑角色信息", httpMethod = "post", response =R.class)
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "SysRole_MenuInOV", value = "原型图中所需参数", paramType = "Object", dataType = "String", required = true)
            }
    )
    public R updateRole(@RequestBody SysRole_MenuInOV sysRole_menuInOV) {
        R r = new R();
        r.setCode(200);
        r.setMassage("编辑成功,编辑后的角色名称为：" + sysRole_menuInOV.getName() + "，编辑后的权限有" + sysRole_menuInOV.getMenu_ids());
        return r;
    }

}